<?php 
/*进货单*/
include('../conn.php');
$userid = (int)$_REQUEST['userid'];
$page = 0;
$pagesize = 10;
//返回数据
$result_data_array = array();
if(!$userid  ){
	$result_data_array['code'] =  -100;
	$result_data_array['msg'] = '用户信息异常';
	echo json_encode($result_data_array);
	exit;

}
if(is_numeric($_REQUEST['page'])){
	$page = $_REQUEST['page'];
}
if(is_numeric($_REQUEST['pagesize'])){
	$pagesize = $_REQUEST['pagesize'];
}
$page*=$pagesize;
$car_array = array();
//查询购物车商品信息
$car_sql = "select "
			."a.carid,a.goodsid,a.shopid,a.fTitle,a.price as car_price,a.sTitle,a.number as car_number"
			.",b.start_num,b.shangjia, b.number as goods_number, b.price as goods_price,b.title,b.images"
			.",c.name,c.open,c.check "
			." from car as a "
			." left join goods as b on b.goodsid = a.goodsid "
			." left join shop as c on c.shopid = a.shopid "
			." where  (a.state = 0 or a.state = 3) and a.userid = ".$userid
			." limit $page,$pagesize";
echo $car_sql;
exit;
$car_query = mysql_query($car_sql);
while ($car_row = mysql_fetch_assoc($car_query)){
	$fTitle = $car_row['fTitle'];
	$sTitle = $car_row['sTitle'];
	$car_row['goodsselect_change'] = 1;

	if( $fTitle  != null && $fTitle != ''){
		$goodsselect_sql = "select price,number from goodsselect where goodsid = ".$car_row['goodsid']." and fTitle = '".$fTitle."'";
		if($sTitle != null && $sTitle != ''){
			$goodsselect_sql .= " and sTitle = '".$sTitle."'";
		}
		$goodsselect_query = mysql_query($goodsselect_sql);
		$goodsselect_row = mysql_fetch_assoc($goodsselect_query);
		if($goodsselect_row){
			$car_row['goods_price'] = $goodsselect_row['price'];
			$car_row['goods_number'] = $goodsselect_row['number'];
		}else{
			$car_row['goods_price'] = 	$car_row['car_price'];
			$car_row['goodsselect_change'] = 0;
		}


	}
	$car_row['images'] = explode(',',$car_row['images'])[0];
	$shopid = $car_row['shopid'];
	if(!$car_array[$shopid]){
		$car_array[$shopid] = array("shopid"=>$shopid,'open'=>$car_row['open'],'check'=>$car_row['check'],'shopname'=>$car_row['name'],'goods_list'=>array());
	}

	unset($car_row['name']);
	unset($car_row['shopid']);
	unset($car_row['open']);
	unset($car_row['check']);
	$car_array[$shopid]['goods_list'][] = $car_row;

	
}
//array_values
$result_data_array['code'] =  200;
$result_data_array['msg'] = '获取成功';
$result_data_array['data'] =  array_values($car_array);
echo json_encode($result_data_array);










 ?>